<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Xrfg\Core\Trading\Account\Models\Coin;

class SystemAccount extends Command
{
    protected $signature = 'SystemAccount';

    protected $description = '生成系统账户';

    public function handle()
    {
        $coins = Coin::all();
        $accounts = \Xrfg\Core\Trading\SystemAccount\Models\SystemAccount::all();

        // 得到所拥有账户和所有币种的coin_id差集
        $diffIds = array_values(array_diff(
            $coins->pluck('id')->toArray(),
            $accounts->pluck('coin_id')->toArray()
        ));

        foreach ($diffIds as $id) {
            $data = [
                \Xrfg\Core\Trading\SystemAccount\Models\SystemAccount::TYPE_RECHARGE => 0,
                \Xrfg\Core\Trading\SystemAccount\Models\SystemAccount::TYPE_WITHDRAW => 0,
                \Xrfg\Core\Trading\SystemAccount\Models\SystemAccount::TYPE_TRADE_FEE => 0,
                \Xrfg\Core\Trading\SystemAccount\Models\SystemAccount::TYPE_WITHDRAW_FEE => 0,
                \Xrfg\Core\Trading\SystemAccount\Models\SystemAccount::TYPE_ACTIVITY => 0,
                \Xrfg\Core\Trading\SystemAccount\Models\SystemAccount::TYPE_SYSTEM => 0,
            ];
            foreach ($data as $k => $v) {
                $systemAccount = new \Xrfg\Core\Trading\SystemAccount\Models\SystemAccount();
                $systemAccount->coin_id = $id;
                $systemAccount->account_type = $k;
                $systemAccount->number = $v;
                $systemAccount->version = 0;
                $systemAccount->save();
            }
        }

    }
}
